package dk.ucn.cm.builder;

import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.model.MultipleCategorySeries;
import org.achartengine.renderer.DefaultRenderer;
import org.achartengine.renderer.SimpleSeriesRenderer;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.view.View;

public class DonutGraph extends Activity implements View.OnClickListener{
	
		RelativeLayout LayoutToDisplayBoard;
		private GraphicalView mChartView2;
		static int count = 2;

		int[] Mycolors = new int[] { Color.parseColor("#D4272D"),
		        Color.parseColor("#6F1717") };
		String[] average = { "SPEED", "FORCE"};
		String[] max = { "SPEED", "FORCE"};

		public Intent execute(Context context, LinearLayout parent, double avg_values[],double max_values[]) {
		    parent.removeAllViews();
		    int[] colors = new int[count];
		    for (int i = 0; i < count; i++) {
		        colors[i] = Mycolors[i];
		    }
		    DefaultRenderer renderer = buildCategoryRenderer(colors);
		    renderer.setShowLabels(false);
		    renderer.setBackgroundColor(Color.BLACK);
		    renderer.setPanEnabled(false);// Disable User Interaction
		    renderer.setScale((float) 1.4);
		    renderer.setInScroll(true); //To avoid scroll Shrink        
		    renderer.setStartAngle(90);
		    renderer.setShowLegend(false);


		    MultipleCategorySeries categorySeries = new MultipleCategorySeries(
		            "Punch Graph");
		    categorySeries.add(average, avg_values);
		    categorySeries.add(max, max_values);

		    mChartView2 = ChartFactory.getDoughnutChartView(context,
		            categorySeries, renderer);

		    parent.addView(mChartView2);

		    return ChartFactory.getDoughnutChartIntent(context, categorySeries,
		            renderer, null);
		}
		
		@Override
		public void onCreate(Bundle savedInstanceState)
		{
			super.onCreate(savedInstanceState);
			setContentView(R.layout.gameboard);				
			
			//Intent intent = getIntent();
			
			//Initialize the layout
			LayoutToDisplayBoard = (RelativeLayout)findViewById(R.id.relative);
			//Intent boardIntent = execute(DonutGraph.this, LayoutToDisplayBoard);
		}
			

		protected DefaultRenderer buildCategoryRenderer(int[] colors) {
		    DefaultRenderer renderer = new DefaultRenderer();
		    for (int color : colors) {
		        SimpleSeriesRenderer r = new SimpleSeriesRenderer();
		        r.setColor(color);
		        renderer.addSeriesRenderer(r);

		    }
		    return renderer;
		}

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			
		}
	}
